﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FeatureModelCore;
using FeatureModelCore.FMTypes;
using Collections.TreeCollections;
using Collections;

namespace FeatureModelTest
{
    public class GenerateTestCases
    {
        #region Mobile Phone Case
        public static readonly string MOBILE_PHONE = "Mobile Phone";
        public static readonly string CALLS = "Calls";
        public static readonly string GPS = "GPS";
        public static readonly string SCREEN = "Screen";
        public static readonly string MEDIA = "Media";
        public static readonly string BASIC = "Basic";
        public static readonly string COLOUR = "Colour";
        public static readonly string HIGH_RESOLUTION = "High Resolution";
        public static readonly string CAMERA = "Camera";
        public static readonly string MP3 = "MP3";

        public static FeatureModelTree GenerateFeatureModel()
        {
            FeatureModelTree fm = new FeatureModelTree();
            FeatureTreeRoot mobilePhone = (FeatureTreeRoot)fm.Root;
            mobilePhone.FeatureName = MOBILE_PHONE;

            // create mobile phone group relationship
            FeatureTreeGroupRelationship mobilePhoneGRMandatory =
                fm.CreateGroupRelationship(mobilePhone, FMTreeGroupRelationshipType.GroupMandatory);
            FeatureTreeGroupRelationship mobilePhoneGROptional =
                fm.CreateGroupRelationship(mobilePhone, FMTreeGroupRelationshipType.GroupOptional);

            // create call
            FeatureTreeNode calls = fm.CreateFeatureNode(mobilePhoneGRMandatory, CALLS);

            // create gps
            FeatureTreeNode gps = fm.CreateFeatureNode(mobilePhoneGROptional, GPS);

            // create screen
            FeatureTreeNode screen = fm.CreateFeatureNode(mobilePhoneGRMandatory, SCREEN);

            FeatureNodeProperty property = fm.CreateProperty(screen, "Border");
            property.PropertyValue = "Black";

            // create media
            FeatureTreeNode media = fm.CreateFeatureNode(mobilePhoneGROptional, MEDIA);

            // screen GR
            FeatureTreeGroupRelationship screenGR = fm.CreateGroupRelationship(
                screen, FMTreeGroupRelationshipType.Alternative);
            // basic
            FeatureTreeNode basic = fm.CreateFeatureNode(screenGR, BASIC);
            // colour
            FeatureTreeNode color = fm.CreateFeatureNode(screenGR, COLOUR);
            // high Resolution
            FeatureTreeNode highResolution = fm.CreateFeatureNode(screenGR, HIGH_RESOLUTION);

            // media Group
            FeatureTreeGroupRelationship mediaGR = fm.CreateGroupRelationship(media, FMTreeGroupRelationshipType.Or);
            // camera
            FeatureTreeNode camera = fm.CreateFeatureNode(mediaGR, CAMERA);
            // mp3
            FeatureTreeNode mp3 = fm.CreateFeatureNode(mediaGR, MP3);

            // create constraint
            fm.CreateConstraint(camera.ID, highResolution.ID, FMCrossTreeConstraintType.Require);
            fm.CreateConstraint(gps.ID, basic.ID, FMCrossTreeConstraintType.Exclude);

            return fm;
        }

        public static FeatureModelTree GenerateFeatureModelWithNoConstraint()
        {
            FeatureModelTree fm = new FeatureModelTree();
            FeatureTreeRoot mobilePhone = (FeatureTreeRoot)fm.Root;
            mobilePhone.FeatureName = MOBILE_PHONE;

            // create mobile phone group relationship
            FeatureTreeGroupRelationship mobilePhoneGRMandatory =
                fm.CreateGroupRelationship(mobilePhone, FMTreeGroupRelationshipType.GroupMandatory);
            FeatureTreeGroupRelationship mobilePhoneGROptional =
                fm.CreateGroupRelationship(mobilePhone, FMTreeGroupRelationshipType.GroupOptional);

            // create call
            FeatureTreeNode calls = fm.CreateFeatureNode(mobilePhoneGRMandatory, CALLS);

            // create gps
            FeatureTreeNode gps = fm.CreateFeatureNode(mobilePhoneGROptional, GPS);

            // create screen
            FeatureTreeNode screen = fm.CreateFeatureNode(mobilePhoneGRMandatory, SCREEN);

            FeatureNodeProperty property = fm.CreateProperty(screen, "Border");
            property.PropertyValue = "Black";

            // create media
            FeatureTreeNode media = fm.CreateFeatureNode(mobilePhoneGROptional, MEDIA);

            // screen GR
            FeatureTreeGroupRelationship screenGR = fm.CreateGroupRelationship(
                screen, FMTreeGroupRelationshipType.Alternative);
            // basic
            FeatureTreeNode basic = fm.CreateFeatureNode(screenGR, BASIC);
            // colour
            FeatureTreeNode color = fm.CreateFeatureNode(screenGR, COLOUR);
            // high Resolution
            FeatureTreeNode highResolution = fm.CreateFeatureNode(screenGR, HIGH_RESOLUTION);

            // media Group
            FeatureTreeGroupRelationship mediaGR = fm.CreateGroupRelationship(media, FMTreeGroupRelationshipType.Or);
            // camera
            FeatureTreeNode camera = fm.CreateFeatureNode(mediaGR,  CAMERA);
            // mp3
            FeatureTreeNode mp3 = fm.CreateFeatureNode(mediaGR, MP3);

            return fm;
        }


        public static FeatureModelTree GenerateFeatureModelOnlyOneAlternativeGroup()
        {
            FeatureModelTree fm = new FeatureModelTree();
            FeatureTreeRoot mobilePhone = (FeatureTreeRoot)fm.Root;
            mobilePhone.FeatureName = MOBILE_PHONE;

            // create mobile phone group relationship
            FeatureTreeGroupRelationship mobilePhoneGR =
                fm.CreateGroupRelationship(mobilePhone, FMTreeGroupRelationshipType.Alternative);

            // create call
            FeatureTreeNode calls = fm.CreateFeatureNode(mobilePhoneGR, CALLS);

            // create gps
            FeatureTreeNode gps = fm.CreateFeatureNode(mobilePhoneGR, GPS);

            // create screen
            FeatureTreeNode screen = fm.CreateFeatureNode(mobilePhoneGR, SCREEN);

            FeatureNodeProperty property = fm.CreateProperty(screen, "Border");
            property.PropertyValue = "Black";

            // create media
            FeatureTreeNode media = fm.CreateFeatureNode(mobilePhoneGR, MEDIA);

            return fm;
        }

        public static FeatureModelTree GenerateFeatureModelOnlyOneOrGroup()
        {
            FeatureModelTree fm = new FeatureModelTree();
            FeatureTreeRoot mobilePhone = (FeatureTreeRoot)fm.Root;
            mobilePhone.FeatureName = MOBILE_PHONE;

            // create mobile phone group relationship
            FeatureTreeGroupRelationship mobilePhoneGR =
                fm.CreateGroupRelationship(mobilePhone, FMTreeGroupRelationshipType.Or);

            // create call
            FeatureTreeNode calls = fm.CreateFeatureNode(mobilePhoneGR, CALLS);

            // create gps
            FeatureTreeNode gps = fm.CreateFeatureNode(mobilePhoneGR, GPS);

            // create screen
            FeatureTreeNode screen = fm.CreateFeatureNode(mobilePhoneGR, SCREEN);

            FeatureNodeProperty property = fm.CreateProperty(screen, "Border");
            property.PropertyValue = "Black";

            // create media
            FeatureTreeNode media = fm.CreateFeatureNode(mobilePhoneGR, MEDIA);

            return fm;
        }

        public static FeatureModelTree GenerateFeatureModelOnlyOneMandatoryGroup()
        {
            FeatureModelTree fm = new FeatureModelTree();
            FeatureTreeRoot mobilePhone = (FeatureTreeRoot)fm.Root;
            mobilePhone.FeatureName = MOBILE_PHONE;

            // create mobile phone group relationship
            FeatureTreeGroupRelationship mobilePhoneGR =
                fm.CreateGroupRelationship(mobilePhone, FMTreeGroupRelationshipType.GroupMandatory);

            // create call
            FeatureTreeNode calls = fm.CreateFeatureNode(mobilePhoneGR, CALLS);

            // create gps
            FeatureTreeNode gps = fm.CreateFeatureNode(mobilePhoneGR, GPS);

            // create screen
            FeatureTreeNode screen = fm.CreateFeatureNode(mobilePhoneGR, SCREEN);

            FeatureNodeProperty property = fm.CreateProperty(screen, "Border");
            property.PropertyValue = "Black";

            // create media
            FeatureTreeNode media = fm.CreateFeatureNode(mobilePhoneGR, MEDIA);

            return fm;
        }
        public static FeatureModelTree GenerateFeatureModelOnlyOneOptionalGroup()
        {
            FeatureModelTree fm = new FeatureModelTree();
            FeatureTreeRoot mobilePhone = (FeatureTreeRoot)fm.Root;
            mobilePhone.FeatureName = MOBILE_PHONE;

            // create mobile phone group relationship
            FeatureTreeGroupRelationship mobilePhoneGR =
                fm.CreateGroupRelationship(mobilePhone, FMTreeGroupRelationshipType.GroupOptional);

            // create call
            FeatureTreeNode calls = fm.CreateFeatureNode(mobilePhoneGR, CALLS);

            // create gps
            FeatureTreeNode gps = fm.CreateFeatureNode(mobilePhoneGR, GPS);

            return fm;
        }

        #endregion
    }
}
